public class test2 {
    //力扣  面试题 01.02 判断是否为重排字符
    public boolean CheckPermutation1(String s1, String s2) {
        if(s1.length()!=s2.length()) return false;
        int[] hash1 = new int[26];
        int[] hash2 = new int[26];

        for(int i = 0;i<s1.length();i++ ){
            char c1 = s1.charAt(i);
            char c2 = s2.charAt(i);
            hash1[c1-'a']++;
            hash2[c2-'a']++;
        }
        for(int i = 0;i<26;i++){
            int value1 = hash1[i];
            int value2 = hash2[i];

            if(value1!=value2){
                return false;
            }
        }
        return true;
    }

    public boolean CheckPermutation2(String s1, String s2) {
        if(s1.length()!=s2.length()) return false;
        int[] hash = new int[26];

        for(int i = 0;i<s1.length();i++ ){
            char c = s1.charAt(i);
            hash[c-'a']++;
        }
        for(int i = 0;i<s2.length();i++){
            char c = s2.charAt(i);
            hash[c-'a']--;

            if(hash[c-'a']<0){
                return false;
            }
        }
        return true;
    }
}
